﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Srv3CodeTool
{
    public partial class FrmOption : Form
    {
        public FrmOption()
        {
            InitializeComponent();
        }

        private Config config = new Config();

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            config.ProjectPath      = txtProjectPath.Text.ToString();
            config.ModulePath       = txtModulePath.Text.ToString();
            config.ModuleResPath    = txtModuleResPath.Text.ToString();
            config.ModePath         = txtModePath.Text.ToString();
            config.UserName         = txtUserName.Text.ToString();
            config.CommentNewCode   = CommCode.Checked;
            config.PtrCheckSub      = cbPtrCheckSub.Checked;
            config.SaveToXmlFile();//保存成xml文件
            Functions.ShowMsgBox("保存设置成功", MSGBOX_TYPE.MSGBOX_TYPE_INFO);
        }

        private void FrmOption_Load(object sender, EventArgs e)
        {
            try
            {
                //读取XML
                config.LoadFromXmlFile();

                //读设置
                txtProjectPath.Text     = config.ProjectPath;
                txtModulePath.Text      = config.ModulePath;
                txtModuleResPath.Text   = config.ModuleResPath;
                txtUserName.Text        = config.UserName;
                txtModePath.Text        = config.ModePath;

                CommCode.Checked        = config.CommentNewCode;
                cbPtrCheckSub.Checked        = config.PtrCheckSub;
            }
            catch (System.Exception ex)
            {
                Log.LogSave(ex.ToString(), LOGTYPE.LOGTYPE_ERROR);
            }

        }

        private void txtProjectPath_Click(object sender, EventArgs e)
        {
        }

        private void btnProjectPath_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.ShowDialog();
            if (folderBrowserDialog1.SelectedPath != "")
            {
                txtProjectPath.Text = folderBrowserDialog1.SelectedPath;
                txtModulePath.Text = folderBrowserDialog1.SelectedPath + "\\Module";
                txtModuleResPath.Text = folderBrowserDialog1.SelectedPath + "\\ModuleRes";
            }
        }

        private void btnModulePath_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.ShowDialog();
            if (folderBrowserDialog1.SelectedPath != "")
                txtModulePath.Text = folderBrowserDialog1.SelectedPath;
        }

        private void btnModuleResPath_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.ShowDialog();
            if (folderBrowserDialog1.SelectedPath != "")
                txtModuleResPath.Text = folderBrowserDialog1.SelectedPath;
        }

        private void btnModePath_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.ShowDialog();
            if (folderBrowserDialog1.SelectedPath != "")
                txtModePath.Text = folderBrowserDialog1.SelectedPath;
        }

    }
}
